/**
 *
 */
package com.googlecode.bip.entity;

import java.util.Comparator;

/**
 * Compare 2 strings
 * @author Claude CHOISNET
 */
class StringComparator implements Comparator<String>
{
    /**
     * Compare 2 Comparable objects
     * @param c0 first object, could be null
     * @param c1 second object, could be null
     * @return 0 if object are 'equals' or are both null
     */
    public static final <T extends Comparable<T>> int compareObject(
            final T c0,
            final T c1
            )
    {
        if( c0 == null ) {
            if( c1 == null ) {
                return 0;
                }
            else {
                return 1;
                }
        }

        return c0.compareTo( c1 );
    }

    /**
     * Compare 2 strings
     * @param s0 first String, could be null
     * @param s1 second String, could be null
     * @return 0 if String have same content or are both null
     */
    public static final int compareString( final String s0, final String s1 )
    {
        return compareObject( s0, s1 );
    }

    @Override
    public int compare( final String s0, final String s1 )
    {
        return compareString( s0, s1 );
    }

}
